home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group98b.txt / 000145_icon-group-sender _Wed Jul 22 17:37:52 1998.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.8.8/8.8.7) with SMTP id RAA27739
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Wed, 22 Jul 1998 17:37:51 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA04329; Wed, 22 Jul 1998 17:37:35 -0700
  7. Message-Id: <3.0.5.32.19980722163020.00a5fbc0@post.its.mcw.edu>
  8. X-Sender: cdt@post.its.mcw.edu
  9. X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.5 (32)
  10. Date: Wed, 22 Jul 1998 16:30:20
  11. To: Kostas Oikonomou <ko@mara.ho.att.com>, icon-group@optima.CS.Arizona.EDU
  12. From: Chris Tenaglia <cdt@post.its.mcw.edu>
  13. Subject: Re: Reading numbers from a file
  14. In-Reply-To: <13747.39630.559540.280143@mara>
  15. Mime-Version: 1.0
  16. Content-Type: text/plain; charset="us-ascii"
  17. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  18. Status: RO
  19. Content-Length: 1212
  20.  
  21. try a variation of this:
  22. ------------------------------
  23. #
  24. # read space delimited lines of numbers
  25. #
  26. procedure main()
  27.   while line := read() do
  28.      {
  29.       numbers := parse(line,' ')                              #split the
  30. line into numbers
  31.       every value := !numbers do process(value)   # process each number
  32.       }
  33.   end
  34.  
  35. #
  36. # parse a string into a list with respect to a delimiter
  37. #
  38. procedure parse(line,delims)
  39.   static chars
  40.   chars  := &cset -- delims
  41.   tokens := []
  42.   line ? while tab(upto(chars)) do put(tokens,tab(many(chars)))
  43.   return tokens
  44.   end
  45.  
  46. #
  47. # whatever
  48. #
  49. procedure process(n)
  50.    ..........
  51.   end
  52.  
  53. -----------------------------------
  54.  
  55. At 03:35 PM 7/20/98 -0400, Kostas Oikonomou wrote:
  56. >
  57. >Hello,
  58. >
  59. >This is probably a dumb question, but there doesn't seem to be an easy way to
  60. >read a numbers from a file with Icon.  I mean a file consisting of lines,
  61. each
  62. >line being a list of numbers (integers or reals), separated by blanks.
  63. >
  64. >I finally wrote my own routine, but I don't want to reinvent thw wheel...
  65. >
  66. >(I looked in the procs/ library, and found pack/unpack in binary.icn.  But I
  67. >don't see how to get unpack to do what I want.)
  68. >
  69. >Thanks for your help.
  70. >
  71. >                Kostas Oikonomou
  72. >
  73. >
  74.  
  75.